package controller

import (
	"fmt"
	"gitee.com/yunduansing/limitsecondkill/service"
	"github.com/kataras/iris/v12"
	"strconv"
)

func Kill(c iris.Context)  {
	productId,err:=strconv.Atoi(c.URLParam("productId"))
	if err!=nil{
		c.JSON(iris.Map{"status":false,"msg":"参数错误"})
		return
	}
	result,err:=service.KillOrder(productId)
	if err!=nil{
		c.JSON(iris.Map{"status":false,"msg":err.Error()})
		fmt.Println(err)
		return
	}
	if !result{
		c.JSON(iris.Map{"status":false,"msg":"秒杀失败。"})
		return
	}
	c.JSON(iris.Map{"status":true,"msg":"秒杀成功。"})
	return
}
